package Top.q3747051.CQPlugin;

import org.bukkit.Bukkit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;

public class SocketLienster extends Thread {
    Socket socket;
    SocketLienster(Socket socket){
        this.socket = socket;
    }
    @Override
    public void run() {
        String msg;
        try {
            InputStream in = socket.getInputStream();
            InputStreamReader isr = new InputStreamReader(in, "UTF-8");
            BufferedReader br = new BufferedReader(isr);
            System.out.println("线程创建成功" );
            while (true) {
                msg = br.readLine();
                if (msg!=null){
                    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),"bc "+msg);
                }else {
                    br.close();
                    isr.close();
                    in.close();
                    System.out.println("线程销毁" );
                    return;
                }

            }

        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
